package com.itbour.service.yjx.user.impl;

import java.util.List;
import java.util.Map;

import com.itbour.com.page.JspPage;
import com.itbour.com.page.Page;
import com.itbour.dao.yjx.user.YjxUserInfoDao;
import com.itbour.dto.yjx.user.YjxThirdUserDto;
import com.itbour.dto.yjx.user.YjxUserDto;
import com.itbour.service.yjx.user.YjxUserInfoService;


// 一键秀 用户管理
public class YjxUserInfoServiceImpl implements YjxUserInfoService {
	
	private YjxUserInfoDao yjxUserInfoDao;
	
	// 获取一键秀用户信息
	public Page getYjxUserInfo(Map<String, Object> parm, Integer pageNo,
			Integer pageSize) {
		Page page = null;
		int skipNum = JspPage.getStartOfPage(pageNo, pageSize);// 获取起始位置
		int totalSize = yjxUserInfoDao.getYjxUserCnt(parm);
		while (totalSize > 0 && totalSize <= skipNum) {
			skipNum = skipNum - pageSize;
			pageNo = pageNo - 1;
		}
		parm.put("pageSize", pageSize);
		parm.put("skipResults", skipNum);
		List<YjxUserDto> data = yjxUserInfoDao.getYjxUsersInfo(parm);
		page = new JspPage(skipNum, totalSize, pageSize, data);
		return page;
	}

	
	public List<YjxUserDto> getUserInfo(Map<String, Object> parm) {
		return yjxUserInfoDao.getYjxUsersInfo(parm);
	}

	// 获取第三方账号 信息
	public Page getYjxThirdUserInfo(Map<String, Object> parm, Integer pageNo,
			Integer pageSize) {
		Page page = null;
		int skipNum = JspPage.getStartOfPage(pageNo, pageSize);// 获取起始位置
		int totalSize = yjxUserInfoDao.getYjxThirdUserInfoCnt(parm);
		while (totalSize > 0 && totalSize <= skipNum) {
			skipNum = skipNum - pageSize;
			pageNo = pageNo - 1;
		}
		parm.put("pageSize", pageSize);
		parm.put("skipResults", skipNum);
		List<YjxThirdUserDto> data = yjxUserInfoDao.getYjxThirdUserInfo(parm);
		page = new JspPage(skipNum, totalSize, pageSize, data);
		return page;
	}

	// 获取一个用户信息
	public List<YjxUserDto> getOneYjxUserInfo(Map<String, Object> parm) {
		parm.put("pageSize", 1);
		parm.put("skipResults", 0);
		return yjxUserInfoDao.getYjxUsersInfo(parm);
	}

	// 修改一键秀 用户信息
	public boolean updYjxUserInfo(Map<String, Object> parm) {
		try {
			yjxUserInfoDao.updYjxUserInfo(parm);
			return true;
		} catch (Exception e) {
			return false;
		}
	}
	
	
	// set和get方法
	public YjxUserInfoDao getYjxUserInfoDao() {
		return yjxUserInfoDao;
	}
	public void setYjxUserInfoDao(YjxUserInfoDao yjxUserInfoDao) {
		this.yjxUserInfoDao = yjxUserInfoDao;
	}
}
